<template>
	<view>
		<tabBar :currentPagePath="this.$route.meta.pagePath"></tabBar>
		<u-navbar title="已办案件">
			<view class="u-nav-slot" slot="left">
			</view>
		</u-navbar>
		<!-- 列表 -->
		<ApproveList ref="ApproveList" :doneList="doneList" @showDetail="showDetail" emptyText="暂无已办案件"></ApproveList>
	</view>
</template>

<script>
	import { queryDoneList } from "@/common/api/flowable/personal.js";
	import { detailsBusinessHistoryList } from "@/common/api/approve/workflow/mf_MyTaskDone.js"
	
	export default {
		data() {
			return {
				// 查询条件
				queryParam: {
					"userid": '',
					"bizenum": 1000,
					"pageNumber": 1,
					"pageSize": 10
				}, 
				// 已办案件
				doneList:[],
				// 用户信息
				user: {}
			};
		},
		async onLoad() {
			this.user = JSON.parse(sessionStorage.getItem("APPROVE_USER"))
			this.queryParam.userid = this.user.userid
			uni.showLoading({
				title: '加载中'
			})
			
			await this.getDoneList()
			
			uni.hideLoading()
		},
		//加载更多
		onPullDownRefresh() {
			// console.log('refresh');
			setTimeout(() => {
				uni.stopPullDownRefresh();
			}, 1000);
			this.doneList = [],
			this.queryParam.pageNumber = 1
			this.getDoneList()
		},
		onReachBottom() {
			if(this.$refs.ApproveList.status == "normal" ){
				return
			}
			this.$refs.ApproveList.status = "loading"
			this.queryParam.pageNumber++
			this.getDoneList()
		},
		methods: {
			//获取列表数据
			async getDoneList(){
				let res = await detailsBusinessHistoryList({ userid: "c17afc971d934f2b952b296c3d477dcb" },this.queryParam)
				if(res.code == 0){
					if(res.data.records && res.data.records.length){
						this.doneList = this.doneList.concat(res.data.records)
						if(this.doneList.length == res.data.total){
							this.$refs.ApproveList.status = "normal"
						}else{
							this.$refs.ApproveList.status = "loadmore"
						}
						
					}else{
						this.doneList = []
					}	
				}
			},
			
			// 查看详情
			showDetail(data) {
				let applyid = data.applyid
				let applyid_bs = data.applyid_bs
				let taskid = data.taskid
				let formid = data.formid
				// let stepid = data.stepid
				let processinstanceid = data.processinstanceid
				uni.navigateTo({
					url:"/pages/approve/done/doneDetail?applyid="+applyid+"&taskid="+taskid+"&formid="+formid+"&applyid_bs="+applyid_bs+"&processinstanceid="+processinstanceid,
				});
			},
			
		},

		components: {
			ApproveList: () => import('@/components/approve_list/ApproveList.vue'),
		},
	}
</script>

<style lang="scss" scoped>
	page {
		background-color: #f5f5f5;
		margin-top: 6px;
	}
</style>